/*
 * Copyright 2004 original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.jbfilter.core.fcomps.delegate;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;

import org.jbfilter.core.CleaningStrategy;
import org.jbfilter.core.EnableStrategy;
import org.jbfilter.core.JbfilterComparatorKeyword;
import org.jbfilter.core.TruncateUnit;
import org.jbfilter.core.fcomps.single.DateFilterComponent;

/**
 * @author Marcus Adrian
 * @see FilterComponentDelegate
 * @see DateFilterComponent
 */
public class DateFilterComponentDelegate<E>
	implements
		DateFilterComponent<E> {

	private List<DateFilterComponent<E>> dfComps = new ArrayList<DateFilterComponent<E>>();
	private SingleFilterComponentDelegate<E, Date> sfCompDelegate = new SingleFilterComponentDelegate<E, Date>();
	
	public void add(DateFilterComponent<E> filterComponent) {
		dfComps.add(filterComponent);
		sfCompDelegate.add(filterComponent);
	}
	public void addAll(Collection<DateFilterComponent<E>> filterComponents) {
		for (DateFilterComponent<E> filterComponent : filterComponents) {
			add(filterComponent);
		}
	}
	@Override
	public void setComparatorKeyword(JbfilterComparatorKeyword comparatorKeyword) {
		for (DateFilterComponent<E> dfComp: dfComps) {
			dfComp.setComparatorKeyword(comparatorKeyword);
		}
	}
	@Override
	public JbfilterComparatorKeyword getComparatorKeyword() {
		return getFirst().getComparatorKeyword();
	}
	@Override
	public void setComparatorKeywordCleanValue(JbfilterComparatorKeyword comparatorKeywordCleanValue) {
		for (DateFilterComponent<E> dfComp: dfComps) {
			dfComp.setComparatorKeywordCleanValue(comparatorKeywordCleanValue);
		}
	}
	@Override
	public JbfilterComparatorKeyword getComparatorKeywordCleanValue() {
		return getFirst().getComparatorKeywordCleanValue();
	}
	@Override
	public Date getValue() {
		return sfCompDelegate.getValue();
	}
	@Override
	public void setValue(Date value) {
		sfCompDelegate.setValue(value);
	}
	@Override
	public Date getValueCleanValue() {
		return sfCompDelegate.getValueCleanValue();
	}
	@Override
	public void setValueCleanValue(Date valueCleanValue) {
		sfCompDelegate.setValueCleanValue(valueCleanValue);
	}
	@Override
	public void setEnabled(boolean enabled) {
		sfCompDelegate.setEnabled(enabled);
	}
	@Override
	public boolean isEnabled() {
		return sfCompDelegate.isEnabled();
	}
	@Override
	public boolean isActive() {
		return sfCompDelegate.isActive();
	}
	@Override
	public void clean() {
		sfCompDelegate.clean();
	}
	@Override
	public void setCleaningStrategy(CleaningStrategy cleaningStrategy) {
		sfCompDelegate.setCleaningStrategy(cleaningStrategy);
	}
	@Override
	public String getId() {
		return sfCompDelegate.getId();
	}
	@Override
	public void setId(String id) {
		sfCompDelegate.setId(id);
	}
	@Override
	public boolean isInverted() {
		return sfCompDelegate.isInverted();
	}
	@Override
	public void setInverted(boolean inverted) {
		sfCompDelegate.setInverted(inverted);
	}
	@Override
	public void setEnableStrategy(EnableStrategy enableStrategy) {
		sfCompDelegate.setEnableStrategy(enableStrategy);
	}
	@Override
	public CleaningStrategy getCleaningStrategy() {
		return sfCompDelegate.getCleaningStrategy();
	}
	@Override
	public EnableStrategy getEnableStrategy() {
		return sfCompDelegate.getEnableStrategy();
	}
	@Override
	public void setNullTestingEnabled(boolean enabled) {
		for (DateFilterComponent<E> dfComp: dfComps) {
			dfComp.setNullTestingEnabled(enabled);
		}
	}
	@Override
	public boolean isNullTestingEnabled() {
		return getFirst().isNullTestingEnabled();
	}
	@Override
	public String getPropertyPath() {
		return getFirst().getPropertyPath();
	}
	@Override
	public void setPropertyPath(String propertyPath) {
		for (DateFilterComponent<E> dfComp: dfComps) {
			dfComp.setPropertyPath(propertyPath);
		}
	}
	@Override
	public void setTruncate(TruncateUnit truncate) {
		for (DateFilterComponent<E> dfComp: dfComps) {
			dfComp.setTruncate(truncate);
		}
	}
	@Override
	public TruncateUnit getTruncate() {
		return getFirst().getTruncate();
	}
	private DateFilterComponent<E> getFirst() {
		for (DateFilterComponent<E> dfComp: dfComps) {
			return dfComp;
		}
		throw new IllegalStateException("No DateFilterComponent set.");
	}

}
